<template>
	<view class="template">
	</view>
</template>

<script>
	import api from 'utils/api'

	export default {
		name: 'create-urlScheme',
		data() {
			return {}
		},
		props: {
			goodsSpu: {
				type: Object,
				default: () => {}
			},
			gType: {
				type: [String || null],
				default: ''
			},
			activityId: {
				type: [String || null],
				default: ''
			}
		},
		methods: {
			shareUrlScheme() {
				const userInfo = uni.getStorageSync('user_info');
				if (userInfo.enable != '1') {
					uni.showModal({
						title: '提示',
						content: '用户不是正常状态，无法进行分享，请联系运营',
						showCancel: false,
						success(res) {}
					});
					return
				}
				const sku = this.goodsSpu.skus[0]
				const sObj = {
					skuId: sku.id,
					userId: userInfo.id,
				}
				if(this.gType=='yc') {
					sObj.activityId = this.activityId
				}
				api.shareInfo(sObj).then(res => {
					let shareId = res.data.id
					// 二维码
					api.ybhshorturl({
						path: '/pages_subject/hwOrder/hw_order',
						query: 'scene=' + shareId
					}).then(res1 => {
						if (res1.data) {
							const urlScheme = JSON.parse(res1.data).openlink
							let content = '立健好物推荐：'+ this.goodsSpu.name + '\n'+'原价：'+ sku.marketPrice +'\n'+ '活动价：'+sku.salesPrice +'\n'+ '购买链接：' + urlScheme
							const ycActName  = uni.getStorageSync('yc_actName')
							if(ycActName){
								content = '【'+ ycActName+ '】'+'\n' + content
							}
							uni.showModal({
								title: '分享链接',
								content: content,
								confirmText: '复制链接',
								showCancel: false,
								success: () => {
									uni.setClipboardData({
										data: content,
										success: function() {
											uni.showToast({
												title: '复制成功',
												icon: 'none',
											});
										}
									});
								},
								fail: (err) => {}
							});
						}
					}).catch(err => {
						uni.showModal({
							title: '提示',
							content: err.data.msg,
							showCancel: false,
							success(res) {}
						});
					})
				})
			},
		}
	}
</script>

<style>
</style>